package com.maxatime.config.boot;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import com.maxatime.dao.ProvincesMapper;
import com.maxatime.pojo.entity.Provinces;
import com.maxatime.util.RedisUtil;

import redis.clients.jedis.Jedis;

//redis存储
@Component
public class RegionalLinkageConfig implements ApplicationRunner {
	
	// 日志
	private Logger log = LogManager.getLogger();
	
	@Autowired
	ProvincesMapper provincesMapper;
	/**
	 * 
	 * <p>Title: run</p>   
	 * <p>Description: redis存储  
	 * @param args
	 * @throws Exception   
	 * @see org.springframework.boot.ApplicationRunner#run(org.springframework.boot.ApplicationArguments)
	 */
    @Override
    public void run(ApplicationArguments args) throws Exception {
    	
    	Provinces provinces = new Provinces();

    	List<Provinces> list = provincesMapper.listByAll(provinces);
    	
    	Map<String, String> m = new HashMap<String, String>();
    	for(Provinces p: list) {
    		m.put(p.getProvinceid(), p.getProvince());
    	}
    	
    	Jedis jedis = RedisUtil.getRedis();
    	jedis.hset("province", m);
    	
    	String pp = jedis.hget("province", "110000");
    	
    	log.info("==province==::: " + pp);

    }
}